layui.use(['jquery', 'layer', 'element'], function () {
    // window.jQuery = window.$ = layui.jquery;
    window.layer = layui.layer;
    window.element = layui.element();

// larry-side-menu向左折叠
    $('.larry-side-menu').click(function () {
        var sideWidth = $('#larry-side').width();
        if (sideWidth === 200) {
            $('#larry-body').animate({
                left: '0'
            }, "fast"); //admin-footer
            $('#larry-footer').animate({
                left: '0'
            }, "fast");
            $('#larry-side').animate({
                width: '0'
            }, "fast");
        } else {
            $('#larry-body').animate({
                left: '200px'
            });
            $('#larry-footer').animate({
                left: '200px'
            });
            $('#larry-side').animate({
                width: '200px'
            }, "fast","swing");
        }
    });
    $(function () {


        $("#adp-logout-bth").click(function () {
            $.post({
                url: "./rs/Login/logout",
                data: JSON.stringify({})
            }).success(function (data) {
                window.location.href = "./login.html";
            });
        });


        // 刷新iframe
        $("#refresh_iframe").click(function () {
            $(".layui-tab-content .layui-tab-item").each(function () {
                if ($(this).hasClass('layui-show')) {
                    $(this).children('iframe')[0].contentWindow.location.reload(true);
                }
            });
        });
        $('#lock').mouseover(function () {
            layer.tips('请按Alt+L快速锁屏！', '#lock', {
                tips: [1, '#FF5722'],
                time: 4000
            });
        })
        // 快捷键锁屏设置
        $(document).keydown(function (e) {
            if (e.altKey && e.which == 76) {
                //layer.alert('开始锁屏！');
                lockSystem();
            }
        });
        function startTimer() {
            var today = new Date();
            var h = today.getHours();
            var m = today.getMinutes();
            var s = today.getSeconds();
            m = m < 10 ? '0' + m : m;
            s = s < 10 ? '0' + s : s;
            $('#time').html(h + ":" + m + ":" + s);
            setTimeout(function () {
                startTimer()
            }, 500);
        }

        // 锁屏状态检测
        function checkLockStatus(locked) {
            // 锁屏

            if (locked == 1) {
                $('.lock-screen').show();
                $('#locker').show();
                $('#layui_layout').hide();
                $('#lock_password').val('');
            } else {
                $('.lock-screen').hide();
                $('#locker').hide();
                $('#layui_layout').show();
            }
        }

        checkLockStatus('0');
        // 锁定屏幕
        function lockSystem() {

            // var url = 'lock.php';
            // $.post(
            // 	   url,
            // 	   function(data){
            // 	   if(data=='1'){
            // 	   	  checkLockStatus(1);
            // 	   }else{
            //     layer.alert('锁屏失败，请稍后再试！');
            // 	   }
            // });
            checkLockStatus(1);
            startTimer();
        }

        //解锁屏幕
        function unlockSystem() {

            checkLockStatus(0);
        }

        // 点击锁屏
        $('#lock').click(function () {
            lockSystem();
        });
        // 解锁进入系统
        $('#unlock').click(function () {

            var password=$("#lock_password").val();
            var validate = SV("Login")("login")({name:session.name,password:password});
            if(validate){
                unlockSystem();
            }else{
                layer.tips("密码错误!", '#lock_password', {
                    tips: [3, 'red']
                });
            }

        });
        // 监控lock_password 键盘事件
        $('#lock_password').keypress(function (e) {
            var key = e.which;
            if (key == 13) {
                unlockSystem();
            }
        });


    });


});


